package com.nuoniu.sibanyun.controller.crm;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.crm.CrmTouch;
import com.nuoniu.sibanyun.entity.dto.CrmTouchSvaeDto;
import com.nuoniu.sibanyun.service.crm.ICrmTouchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 联系记录 前端控制器
 * </p>
 *
 * @author baiqiang
 * @since 2020-06-15
 */
@RestController
@RequestMapping("/crm/touch")
@Api(value="联系记录 ",tags={"联系记录"})
public class CrmTouchController extends BaseController {

    @Autowired
    private ICrmTouchService touchService;

    @GetMapping("pageList")
    @ApiOperation(value = "获取跟进记录列表", tags = "APP_联系记录")
    public HttpResult<CrmTouch> pageList(Page page, CrmTouch touch) {
        return HttpResult.ok(touchService.pageList(page, touch));
    }

    @GetMapping("/detail")
    @ApiOperation(value = "详情",tags = "APP_联系记录")
    public HttpResult<CrmTouch> detail(Integer id) {
        if(null == id || id < 1){
            throw new NuoNiuException("参数错误");
        }
        return HttpResult.ok(touchService.getById(id));
    }

    /**
     * 保存联系记录
     * @author 小啊刚
     * @date 2020/6/23
     */
    @PostMapping("save")
    @ApiOperation(value = "保存",tags = "APP_联系记录")
    public HttpResult saveCrmTouch(@RequestBody CrmTouchSvaeDto touchSaveDto) {
        touchService.saveCrmTouche(touchSaveDto);
        return HttpResult.ok();
    }

//    /**
//     * 删除联系记录
//     * @author 小啊刚
//     * @date 2020/6/23
//     */
//    @DeleteMapping("delete")
//    public HttpResult delete(Integer id) {
//        touchService.removeById(id);
//        return HttpResult.ok();
//    }

    /**
     * 停用联系记录
     * @author 小啊刚
     * @date 2020/6/23
     */
    @GetMapping("disable")
    @ApiOperation(value = "停用",tags = "APP_联系记录")
    public HttpResult disable(String ids) {
        touchService.disable(ids);
        return HttpResult.ok("停用联系记录成功");
    }

    /**
     * 启用联系人
     * @author 小啊刚
     * @date 2020/6/23
     */
    @GetMapping("enable")
    @ApiOperation(value = "启用",tags = "APP_联系记录")
    public HttpResult enable(String ids) {
        if (StringUtils.isNoneBlank(ids)) {
            for (String id : ids.split(",")) {
                CrmTouch crmTouch = new CrmTouch();
                crmTouch.setId(Long.valueOf(id));
                crmTouch.setStatus(0);
                touchService.updateById(crmTouch);
            }
        }
        return HttpResult.ok("停用联系记录成功");
    }
}
